﻿@{
    ViewBag.Title = "素材/作品/组件审核详情";
}
@section headerSection{
    <link href="~/Resources/mainFrame/js/plugins/zTree3/css/metroStyle/metroStyle.css" rel="stylesheet" />
    <script src="~/Resources/mainFrame/js/plugins/zTree3/js/jquery.ztree.core.min.js"></script>
    <script src="~/Resources/mainFrame/js/plugins/zTree3/js/jquery.ztree.excheck.min.js"></script>
    <script src="~/Resources/mainFrame/js/plugins/zTree3/js/jquery.ztree.exedit.min.js"></script>
    <script src="~/Resources/tools/search_zTree.js"></script>
    <style>
        #unitTree{
            width:400px;
            height:300px;
            padding:0;
            border:1px solid #E7EAEC;
            background-color:#FFFFFF;
            position:fixed;
            z-index:9;
            overflow:auto;
            display:none;
        }
    </style>
}
<div id="entryHtml" class="wrapper animated fadeInRight autoHeight">
    <!-- Panel Other -->
    <div class="row autoHeight" style="background-color: #fff;">
        <div class="col-sm-12 col-sm-leftRight">
            <form class="form-horizontal m-t" id="orgFormTable" method="post" style="margin-bottom:120px;" autocomplete="off">
                <div class="form-group">
                    <label class="col-sm-3 control-label">@ViewBag.pageName 标题<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <input id="file_name" name="file_name" type="text" required="" aria-required="true" class="form-control input-sm" placeholder="请输入标题" title="请输入标题" />
                    </div>
                    <label class="col-sm-2 control-label">浏览次数<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <input id="browse_num" name="browse_num" type="text" class="form-control input-sm" placeholder="浏览次数" title="浏览次数" required="" aria-required="true" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">别名：</label>
                    <div class="col-sm-3">
                        <textarea class="form-control" id="alias_name" name="alias_name" rows="2" placeholder="请输入别名" title="请输入别名"></textarea>
                    </div>
                    <label class="col-sm-2 control-label">点赞次数<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <input id="vr_star" name="vr_star" type="text" class="form-control input-sm" placeholder="点赞次数" title="点赞次数" required="" aria-required="true" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">简介：</label>
                    <div class="col-sm-3">
                        <textarea class="form-control" id="file_note" name="file_note" rows="2" placeholder="请输入简介" title="请输入简介"></textarea>
                    </div>
                    <label class="col-sm-2 control-label">下载次数<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <input id="down_number" name="down_number" type="text" class="form-control input-sm" placeholder="下载次数" required="" aria-required="true" title="下载次数" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">推荐<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <select id="is_recommend" name="is_recommend" title="请选择推荐状态" data-live-search="true" class="form-control input-sm selectpicker" placeholder="请选择推荐状态" disabled="disabled" required="" aria-required="true">
                            <option value="0" selected>不推荐</option>
                            <option value="1">推荐</option>
                        </select>
                    </div>
                    <label class="col-sm-2 control-label">评论次数<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <input id="talk_num" name="talk_num" type="text" class="form-control input-sm" placeholder="评论次数" required="" aria-required="true" title="评论次数" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">权限：</label>
                    <div class="col-sm-3">
                        <select id="folder_limit" name="folder_limit" title="请选择权限" class="form-control input-sm selectpicker" placeholder="请选择权限" style="padding: 5px 10px;" required="" aria-required="true">
                            <option value="">空</option>
                        </select>
                    </div>
                    <label class="col-sm-2 control-label">属性<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <select id="fileStatus" name="fileStatus" title="请选择属性" class="form-control input-sm selectpicker" placeholder="请选择属性" disabled="disabled">
                            <option value="0">私有</option>
                            <option value="1">公开</option>
                            <option value="2">重新审核</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">编辑：</label>
                    <div class="col-sm-3">
                        <select id="allowEdit" name="allowEdit" title="请选择编辑权限" class="form-control input-sm selectpicker" placeholder="请选择编辑权限" style="padding: 5px 10px;">
                            <option value="0">不可编辑</option>
                            <option value="1">允许编辑</option>
                        </select>
                    </div>
                    <label class="col-sm-2 control-label">审核通过时间：</label>
                    <div class="col-sm-3">
                        <input id="approve_time" name="approve_time" disabled="disabled" type="text" class="form-control input-sm" placeholder="审核通过时间" title="审核通过时间" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label pro-duct">产品格式<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3 pro-duct">
                        <select id="pro_form" name="pro_form" title="请选择产品格式" class="form-control input-sm selectpicker" required="" aria-required="true" placeholder="请选择产品格式">
                            <option value="1" selected>VR</option>
                            <option value="2">虚拟仿真</option>
                            <option value="3">AR</option>
                        </select>
                    </div>
                    <label class="col-sm-3 control-label pro-mater">素材格式<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3 pro-mater">
                        <select id="mater_type" name="mater_type" title="请选择素材格式" class="form-control input-sm selectpicker" required="" aria-required="true" placeholder="请选择素材格式">
                            <option value="1" selected>VR</option>
                            <option value="2">虚拟仿真</option>
                            <option value="3">AR</option>
                        </select>
                    </div>
                    <label class="col-sm-2 control-label">审核人：</label>
                    <div class="col-sm-3">
                        <input id="approve_name" name="approve_name" disabled="disabled" type="text" class="form-control input-sm" placeholder="审核人" title="审核人" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">产品类别<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <select id="pro_type" name="pro_type" title="请选择产品类别" class="form-control input-sm selectpicker" required="" aria-required="true" placeholder="请选择产品类别">
                            @*<option value="1" selected>VRPPT</option>
                            <option value="2">创客</option>
                            <option value="3">头记</option>
                            <option value="4">校史馆</option>*@
                        </select>
                    </div>
                    <label class="col-sm-2 control-label">最后修改时间：</label>
                    <div class="col-sm-3">
                        <input id="update_time" name="update_time" disabled="disabled" type="text" class="form-control input-sm" placeholder="最后修改时间" title="最后修改时间" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">@ViewBag.pageName 适合分类<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <select id="file_classify" name="file_classify" title="请选择适合分类" class="form-control input-sm selectpicker" data-live-search="true" required="" aria-required="true" placeholder="请选择适合分类"></select>
                        <!-- 素材类型 -->
                        <input type="hidden" id="file_id" name="file_id" value="" />
                    </div>
                    <label class="col-sm-2 control-label">最后修改人：</label>
                    <div class="col-sm-3">
                        <input id="update_name" name="update_name" disabled="disabled" type="text" class="form-control input-sm" placeholder="最后修改人" title="最后修改人" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">目录导航<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <input id="folder_name" name="folder_name" type="text" required="" aria-required="true" class="form-control input-sm" placeholder="请选择目录导航" title="请选择目录导航" />
                        <div id="unitTree" class="col-sm-3"></div>
                        <input id="folder_id" name="folder_id" type="hidden" />
                        <input id="folder_path" name="folder_path" type="hidden" />
                    </div>
                    <label class="col-sm-2 control-label">上传时间：</label>
                    <div class="col-sm-3">
                        <input id="create_time" name="create_time" disabled="disabled" type="text" class="form-control input-sm" placeholder="上传时间" title="上传时间" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">所属单位：</label>
                    <div class="col-sm-3">
                        <select id="unit_code" name="unit_code" title="请选择所属单位" class="form-control input-sm selectpicker" placeholder="请选择所属单位" style="padding: 5px 10px;">
                            <option value="">空</option>
                        </select>
                        <input type="hidden" id="org_unit" name="org_unit" />
                    </div>
                    <label class="col-sm-2 control-label">作者：</label>
                    <div class="col-sm-3">
                        <input id="folder_author" name="folder_author" disabled="disabled" type="text" class="form-control input-sm" placeholder="编号" title="编号" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">商品来源<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <select id="supplyType" name="supplyType" title="请选择商品来源" data-live-search="true" class="form-control input-sm selectpicker" placeholder="请选择商品来源" required="" aria-required="true">
                            <option value="0" selected>个人</option>
                            <option value="1">自营</option>
                        </select>
                    </div>
                    <label class="col-sm-2 control-label">代码：</label>
                    <div class="col-sm-3">
                        <input id="folder_num" name="folder_num" type="hidden"  class="form-control input-sm" placeholder="代码" title="代码" />
                        <input id="file_code" name="file_code"  type="text" class="form-control input-sm" placeholder="代码" title="代码"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">状态<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
                    <div class="col-sm-3">
                        <select id="file_status" name="file_status" title="请选择状态" data-live-search="true" class="form-control input-sm selectpicker" disabled="disabled" placeholder="请选择状态" required="" aria-required="true">
                            <option value="0">私有</option>
                            <option value="1">待审核</option>
                            <option value="3">免费共享</option>
                            <option value="4">下架</option>
                            <option value="5">已上架</option>
                            <option value="6">审核未通过</option>
                        </select>
                    </div>
                    <label class="col-sm-2 control-label">价格：</label>
                    <div class="col-sm-3">
                        <input id="file_money" name="file_money" disabled="disabled" type="text" class="form-control input-sm" placeholder="价格" title="价格" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">外链：</label>
                    <div class="col-sm-8">
                        <textarea class="form-control" id="out_link" name="out_link" rows="2" placeholder="请输入外链" title="请输入外链"></textarea>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">审批意见：</label>
                    <div class="col-sm-8">
                        <textarea class="form-control" id="approve_note" name="approve_note" rows="2" placeholder="请输入审批意见" title="请输入审批意见"></textarea>
                    </div>
                </div>
            </form>
        </div>
    </div>  
</div>
@section footSection{  
    <script>
        var _folderName = null;
        var fileId, isread, isFolder = false, doc_type, pageType, pro_type, sourceType, $pageType;
        var entryType = $.getUrls("entryType");
        var unitzTree;
        var entryManager = {
            initPage: function () {
                showLoadBoxs();
                if (!entryManager.initData())
                    return false;
                entryManager.bindZtree();
                entryManager.initSelect();
                entryManager.initForm();
                entryManager.bindEvent();
                delLoadBoxs();
            },
            initData: function () {
                fileId = $.getUrls("file_id");
                isread = $.getUrls("read");
                if (!fileId) {
                    layer.msg("作品ID异常！");
                    return false;
                }
                pageType = $.getUrls("pageType");
                doc_type = $.getUrls("doc_type");
                pro_type = $.getUrls("pro_type");
                $pageType = pageType;
                if (!pageType)
                    pageType = "";
                //待审核时去掉所属项目
                if (doc_type === 5)
                    pageType = "";
                if (pageType === "VRManager") {
                    sourceType = "mater";
                    $('.pro-duct').css("display", "none");
                }
                else if (pageType === "VRWorks") 
                    $('.pro-mater').css("display", "none");
                else {
                    $('.pro-mater').css("display", "none");
                    $('.pro-duct select').attr("disabled", "disabled");
                }
                return true;
            },
            initSelect: function () {
                //产品类别
                $('#pro_type').initSelectcontrol("vrProType");
                $('#file_classify').initSelectcontrol("docClassify");
                $('#folder_limit').initSelectcontrol("docLimits");
                if ($('#mater_type'))
                    $('#mater_type').initSelectcontrol("docMaterType", true);
                $.ajax({
                    url: ctx + '/SysCommon/GetDictionaryByCode',
                    type: "post",
                    cache: false,
                    async: false,
                    data: { fieldCode: 'SysUserUnit' },
                    dataType: 'json',
                    success: function (data) {
                        if (data.Statu === 1) {
                            layer.msg(data.Msg, { icon: 5 });
                            return false;
                        }
                        var itemStr = "";
                        $.each(data.Data, function (i, item) {
                            itemStr += "<option value='" + item.code_value + "'>" + item.code_name + "</option>";
                        });
                        $('#unit_code').append(itemStr);
                        $('.selectpicker').selectpicker({ size: 6 });
                        $('.selectpicker').selectpicker('refresh');
                    },
                    error: function () {
                        layer.msg('数据异常~', { icon: 5 });
                    }
                });
                //初始化状态
                if (entryType && entryType === "approve") {
                    var fileStatus = "<option value='5' selected=''>通过</option><option value='6'>不通过</option>";
                    $("#file_status").removeAttr("disabled");//开启状态
                    $("#is_recommend").removeAttr("disabled");//开启推荐
                    $("#file_status").empty();
                    $('#file_status').selectpicker('refresh');
                    $('#file_status').append(fileStatus);
                    $('#file_status').selectpicker('refresh');
                }
            },
            initForm: function () {
                $('#orgFormTable').resetHideValidForm();
                $.ajax({
                    type: 'post',
                    url: ctx + '/SourceManager/GetEntryData/' + fileId,
                    dataType: 'json',
                    async: false,
                    success: function (data) {
                        if (data.Statu === 0) {
                            var result = data.Data.info, folder = data.Data.folder;
                            _folderName = folder.folder_name;
                            if (result) {
                                if (entryType && entryType === "approve") {
                                    //审核
                                    result.is_recommend = "0";//默认推荐
                                    result.file_status = "5";//默认审核通过
                                    //folder.folder_name = "";
                                } else {
                                    if (result.is_recommend)
                                        result.is_recommend = "1";
                                    else
                                        result.is_recommend = "0";
                                }
                                if (result.approve_time)
                                    result.approve_time = $.formatByDate(result.approve_time);
                                if (result.update_time)
                                    result.update_time = $.formatByDate(result.update_time);
                                if (result.create_time)
                                    result.create_time = $.formatByDate(result.create_time);
                                if (result.allow_edit)
                                    result["allowEdit"] = "1";
                                else
                                    result["allowEdit"] = "0";
                                switch (result.file_status) {
                                    case 0:
                                    case 1:
                                    case 3:
                                    case 5: $('#fileStatus').removeAttr("disabled"); break;
                                    default: $('#fileStatus').attr("disabled", "disabled"); break;
                                }
                                if (result.file_status != 0)
                                    result["fileStatus"] = "1";
                                else
                                    result["fileStatus"] = "0";
                            }
                            $('#orgFormTable')[0].reset();//重置表单
                            $('#orgFormTable').LoadForm(result);//表单填充数据
                            $('#folder_name').val(folder.folder_name);
                            $('#folder_id').val(folder.folder_id);
                            $('#folder_path').val(folder.folder_path);
                            //判断是否只读
                            if (isread) {
                                //只读
                                $('#orgFormTable').find("input,textarea").attr("disabled", true);
                                $('#orgFormTable').find("select").next("div").children("button").attr("disabled", true);
                            }
                            $('button.disabled ').css("background-color", "#EEEEEE");
                        }
                        else
                            layer.msg(data.Msg, { icon: 5 });
                    }
                });
            },
            saveForm: function (indexForm) {
                //校验审批是否通过
                var file_status = $('#file_status').val(), approve_note = $('#approve_note').val();
                if (file_status === "6") {
                    if (!approve_note || !approve_note.trim()) {
                        layer.alert("温馨提示：审批不通过时需要填写审批意见！", { ison: 5 });
                        return false;
                    }
                    if(approve_note.length>200){
                        layer.alert("温馨提示：审批意见最多200个字！", { ison: 5 });
                        return false;
                    }
                }
                if ($('#orgFormTable').valid()) {
                    var allow_edit = ($('#allowEdit').val() === "0") ? false : true, fileStatus = $('#fileStatus').attr("disabled");
                    var $data = {
                        allow_edit: allow_edit,
                        status: $('#fileStatus').val(),
                        file_status: $('#file_status').val(),
                        entryType: entryType,
                        saveType: 'approve',
                        sourceType: sourceType
                    };
                    if (fileStatus)
                        $data["fileStatus"] = $('#file_status').val();
                    //验证通过
                    if (!$('#file_code').val()) {
                        layer.alert("代码项唯一并且必填！");
                        return false;
                    }
                    //单位名称
                    $('#org_unit').val($('#unit_code').find("option:selected").text());//所属单位 名称
                    $('#orgFormTable').ajaxSubmit({
                        url: ctx + '/SourceManager/SaveEntryData',
                        type: "post",
                        data: $data,
                        dataType: "json",
                        beforeSubmit: function (arr, $form, options) {
                            layer.msg("提交数据~", { icon: 1, time: 5000 });
                        },
                        success: function (result, status, xhr, $form) {
                            if (result.Statu === 0) {
                                layer.msg("更新成功！", { icon: 6 });
                                window.parent.docManager.closeIndexForm(indexForm);
                                return true;
                            }
                            else {
                                layer.alert(result.Msg, { icon: 5 });
                                return false;
                            }
                        },
                        error: function (xhr, status, error, $form) {
                            layer.msg("保存失败~", { icon: 5 });
                        }
                    });
                } else {
                    layer.msg("请检查必填项是否填写正确！", { icon: 5 });
                    return false;
                }
            },
            //绑定事件
            bindEvent:function(){
                $('#folder_name').on('click', function (event) {
                    if (!isFolder) {
                        //打开
                        $('#unitTree').slideDown();
                        isFolder = true;
                    } else {
                        //关闭
                        $('#unitTree').slideUp();
                        isFolder = false;
                    }
                    event.stopPropagation();
                });
                $('#entryHtml').on('click', function () {
                    //if (isFolder) {
                    //    $('#unitTree').slideUp();
                    //    isFolder = false;
                    //}
                });
                $('#file_status').on('change', function () {
                    var status = $(this).val();
                    if (status != 6)
                        $('#folder_name').val('');
                    else
                        $('#folder_name').val(_folderName);
                });
            },
            //素材、作品树
            //2.2采用Ztree初始化文档树
            bindZtree: function () {
                var setting = {
                    view: {
                        showIcon: true,
                        selectedMulti: false,
                        fontCss: getFontCss
                    },
                    edit: {
                        enable: true,
                        showRemoveBtn: false,
                        showRenameBtn: false
                    },
                    async: {
                        enable: true,
                        dataType: "text",
                        type: "post",
                        url: ctx + "/DocManager/GetDocTreeData?pro_type=" + pro_type + "&doc_type=" + doc_type + "&isNum=1&entryType=approve&pageType=" + $pageType,
                        autoParam: ["id"]
                    },
                    data: {
                        key: { title: "name", name: "name" },
                        simpleData: { enable: true, idKey: "id", pIdKey: "pId", rootPId: 0 }
                    },
                    check: {
                        enable: false,
                        autoCheckTrigger: true,
                        chkStyle: "checkbox",
                        chkboxType: { "Y": "p", "N": "ps" }
                    },
                    callback: {
                        onAsyncError: function () {
                            layer.msg("初始化单位结构树失败~", { icon: 5 });
                        },
                        onAsyncSuccess: function (event, treeId, treeNode, msg) {
                        },
                        onClick: function (event, treeId, treeNode) {
                            $('#unitTree a').css("color", "#333");
                            $('#' + treeNode.tId + '_a').css("color", "#ffffff");
                            $('#folder_id').val(treeNode.id);
                            $('#folder_path').val(treeNode.folder_path);
                            $('#unitTree').slideUp();
                            var folderName = treeNode.name;
                            _folderName = folderName;
                            if (folderName.indexOf('(') > -1){
                                _folderName = folderName.substring(0, folderName.indexOf('('));//_folderName 
                                $('#folder_name').val(_folderName);
                            }
                            else 
                                $('#folder_name').val(folderName);
                            isFolder = false;
                        }
                    }
                };
                unitzTree = $("#unitTree").initzTreeView(setting, 'ushow');
            }
        }
        $(function(){
            //初始化Page
            entryManager.initPage();
        });
    </script>
}

